package com.heima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.heima.mapper.RegionMapper;
import com.heima.pojo.dto.AddRegionDTO;
import com.heima.pojo.dto.ReceiveDto;
import com.heima.pojo.vo.PagingVO;
import com.heima.pojo.vo.RegionVO;
import com.heima.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RegionServicelmpl implements RegionService {
    @Autowired
    private RegionMapper regionMapper;
    /**查询地区
     * @param receiveDto
     * @return
     */
    @Override
    public PagingVO SelectRegion(ReceiveDto receiveDto) {
        PageHelper.startPage(receiveDto.getPageIndex(),receiveDto.getPageSize());
        Page<RegionVO> regionVO = regionMapper.SelectRegion(receiveDto.getName());
        PagingVO pagingVo = new PagingVO<>();
        pagingVo.setCurrentPageRecords(regionVO);
        pagingVo.setPageIndex(receiveDto.getPageIndex());
        pagingVo.setPageSize(receiveDto.getPageSize());
        pagingVo.setTotalCount((int) regionVO.getTotal());
        pagingVo.setTotalPage( regionVO.getPages());
        return pagingVo;

    }

    /**新增地区
     * @param addRegionDTO
     * @return
     */
    @Override
    public Boolean addRegion(AddRegionDTO addRegionDTO) {
        return regionMapper.addRegion(addRegionDTO);
    }

    /**删除区域
     * @param regionId
     * @return
     */
    @Override
    public Boolean deleteRegion(String regionId) {
        return regionMapper.deleteRegion(regionId);

    }


}
